package com.cxg.fairy.ec.main.personal.coupon;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.alibaba.fastjson.JSONObject;
import com.cxg.fairy.ec.main.order.PostOrderDelegate;

import java.util.ArrayList;

/**
 * Created by CFairy
 */

public class AllCouponTabPagerAdapter extends FragmentStatePagerAdapter {

    private final ArrayList<String> TAB_TITLES = new ArrayList<>();

    private AllCouponTabDelegate mDelegate = null;

    public AllCouponTabPagerAdapter(FragmentManager fm, JSONObject object, AllCouponTabDelegate delegate) {
        super(fm);
        mDelegate = delegate;
        final int numNotUsed = object.getInteger("numNotUsed");
        final int numUsed = object.getInteger("numUsed");
        final int numExpired = object.getInteger("numExpired");
        TAB_TITLES.add("未使用(" + numNotUsed + ")");
        TAB_TITLES.add("已使用(" + numUsed + ")");
        TAB_TITLES.add("已过期(" + numExpired + ")");
    }

    @Override
    public Fragment getItem(int position) {
        if (position == 0) {
            return AllCouponListDelegate.create(0,mDelegate);
        } else if (position == 1) {
            return AllCouponListDelegate.create(1,mDelegate);
        } else if (position == 2) {
            return AllCouponListDelegate.create(2, mDelegate);
        }
        return null;
    }

    @Override
    public int getCount() {
        return TAB_TITLES.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return TAB_TITLES.get(position);
    }
}
